package Java8;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Reduce {

    public static void main(String[] args) {
        int result = Stream.of(1, 2, 3).reduce(0, (acc, element) -> acc + element);
        System.out.println(result);
        Stream.of(1, 2, 3).collect(Collectors.toCollection(ArrayList::new));
        Optional<Integer> opt = Stream.of(1, 2, 3).collect(Collectors.maxBy(Comparator.comparing(e -> e + 1)));
        System.out.println(opt.get());
        System.out.println(Stream.of(1, 2, 3).collect(Collectors.averagingDouble(e -> e + 1)));

        System.out.println(IntStream.of(1, 2, 3).summaryStatistics());
    }

}
